package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.ShopDetail;
import com.myapp.ruyixing.model.ShopDetail.DetailItem;

public class ShopDetailParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {

		ShopDetail shopDetail = new ShopDetail();
		shopDetail.list = new ArrayList<ShopDetail.DetailItem>();

		ModelParser.parseModel(shopDetail, jsonObject);

		JSONObject data = jsonObject.optJSONObject("data");
		shopDetail.price = data.optString("price", "");
		shopDetail.taste = data.optString("taste", "");
		shopDetail.favorite = data.optInt("favorite", 0);
		shopDetail.environment = data.optString("environment", "");
		shopDetail.service = data.optString("service", "");
		shopDetail.name = data.optString("name", "");
		shopDetail.distance = data.optLong("distance", 0);
		shopDetail.score = data.optInt("score", 0);
		shopDetail.picurl = data.optString("picurl", "");
		shopDetail.lat = data.optDouble("lat", 0.0);
		shopDetail.lon = data.optDouble("lon", 0.0);
		shopDetail.othershop = data.optString("othershop", "");

		JSONArray list = data.optJSONArray("list");

		for (int i = 0; list != null && i < list.length(); i++) {
			JSONObject object = list.optJSONObject(i);
			if (object != null) {

				DetailItem item = new DetailItem();
				item.content = object.optString("content", "");
				item.id = object.optString("id", "");
				item.title = object.optString("title", "");
				item.type = object.optString("type", "");
				item.avatar = object.optString("avatar", "");
				item.datetime = object.optString("datetime", "");
				item.score = object.optInt("score", 0);
				item.total = object.optInt("total", 0);
				item.username = object.optString("username", "");
				shopDetail.list.add(item);
			}
		}

		return shopDetail;

	}
}
